package com.aviva.app.user;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;

@ManagedBean
public class UserView {
	@ManagedProperty("#{userService}")
	private UserService userService;
	private List<User> users=new ArrayList<User>();
	private User selectedUser = new User();
	
	@PostConstruct
	public void init(){
		users = userService.getAllUsers();
		
	}
	public void saveUser(){
		userService.persist(getSelectedUser());	
	}
	public void createUser(){
		User selectedUser = getSelectedUser();
		selectedUser.setId(null);
		userService.createUser(selectedUser);
	}
	public void prepareNewUser(){
		setSelectedUser(new User());
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public User getSelectedUser() {
		return selectedUser;
	}

	public void setSelectedUser(User selectedUser) {
		this.selectedUser = selectedUser;
	}

	
	
}
